namespace SubhadraSolutions.Sharp.Logging.Common
{
    using SubhadraSolutions.Sharp.Logging.Contracts;
    using SubhadraSolutions.Sharp.Utils.Collections.Concurrent;
    using System;

    public sealed class ImmediateLogStore : ILogBuffer
    {
        #region Fields

        private readonly StoreFlushEventArgs<LogStoreItem> _args;
        private readonly LogStoreItem[] _array = new LogStoreItem[1];

        #endregion Fields

        #region Constructors

        public ImmediateLogStore()
        {
            _args = new StoreFlushEventArgs<LogStoreItem>(_array);
        }

        #endregion Constructors

        #region Events

        public event EventHandler<StoreFlushEventArgs<LogStoreItem>> OnStoreFlush;

        #endregion Events

        #region Methods

        public void Dispose()
        {
        }

        public bool Write(LogStoreItem item)
        {
            if (OnStoreFlush != null)
            {
                _array[0] = item;
                OnStoreFlush(this, _args);
            }
            return true;
        }

        #endregion Methods
    }
}